package com.serve.oa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.serve.oa.entity.SysMenu;
import com.serve.oa.mapper.SysMenuMapper;
import com.serve.oa.service.SysMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author __tyw
 * @since 2022-11-16
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
    public List<SysMenu> tree(){
        List<SysMenu> meuns =  this.list(new QueryWrapper<SysMenu>().orderByAsc("orderNum"));

        ArrayList<SysMenu> newMens =  new ArrayList<>();
        meuns.forEach(i->{

            meuns.forEach(b->{

                if (i.getId() == b.getParentId()) {
                    i.getChildren().add(b);
                }
            });
            if(i.getParentId() == 0){
                newMens.add(i);
            }


        });
        return newMens;
    }

}
